/*********************************************************************************
 *      Copyright:  (C) 2022 xiezongyi<1764417007@qq.com>
 *                  All rights reserved.
 *
 *       Filename:  tlv_client.h
 *    Description:  This file 
 *                 
 *        Version:  1.0.0(11/08/22)
 *         Author:  xiezongyi <1764417007@qq.com>
 *      ChangeLog:  1, Release initial version on "11/08/22 12:24:41"
 *                 
 ********************************************************************************/
#ifndef _TLV_CLIENT_H_
#define _TLV_CLIENT_H_

#define PACK_HEADER        0xFD

/* TLV packet fixed segement size, 1B Head, 1B Tag, 1B length, 2B CRC16, total 5B. */
#define TLV_FIXED_SIZE     5

/* TLV packet Minimum size is fixed bytes + 1 byte data */
#define TLV_MIN_SIZE       (TLV_FIXED_SIZE+1)
#define TLV_MAX_SIZE       32    /* all TLV packet length are no more than 32 bytes */


/* Tag definition */
enum
{
    TAG_SN=1,
    TAG_TEMP,
    TAG_TIME,
};

typedef struct tlv_buf_s
{
    char                   buf[256];
    int                    len;  /* data length */
    int                    size; /* buffer size */
} tlv_buf_t;

/* Packet 3 TLV message together: with SN, temperature, date&time */
int packtlv_msg(tlv_buf_t *tlv, char *sn, u_int16_t temp, struct tm *tm);

/* Packet TLV message for temperature */
int packtlv_temp(char *buf, int size, u_int16_t temp);

/* Packet TLV message for date time */
int packtlv_time(char *buf, int size, struct tm *tm);

/* Packet TLV message for SN */
int packtlv_sn(char *buf, int size, char *sn);

/* print buf data in hex and string mode  */
void dump_buf(char *data, int len);

#endif


